(function () {
   const href = location.href,
      url = href.match(/:\/\/.+?\//)[0]
   let prot
   if (href.includes('https://'))
      prot = 'wss'
   else
      prot = 'ws'
   const wsUrl = prot + url
   function init() {
      try {
         const ws = new WebSocket(wsUrl)
         ws.onopen = function () {
            console.log('建立webSocket连接');
         }
         ws.onmessage = function (msg) {
            const data = JSON.parse(msg.data)
            if (data.modifyFile) {
               data.modifyFile
               location.reload()
            }
         }
         ws.onclose = function () {
            console.log('正在尝试重连');
            setTimeout(init, 1000)
         }
      } catch {
         return false
      }
      return true
   }
   init()
})()
